var t = getApp();

Page({
    data: {
        clause: [],
        clauselist: [],
        title: "",
        parties: "",
        ht: {},
        url: "",
        url2: "",
        id: "",
        sessin: ""
    },
    onLoad: function(e) {
        var a = this, i = e.id, n = e.url, o = e.url2, l = e.sessin;
        this.setData({
            url: n,
            url2: o,
            id: i,
            sessin: l,
            Listurl: e.Listurl,
            TopName: e.TopName
        });
        var r = t.globalData.htGet;
        if (i == r.id) {
            this.setData({
                ht: r
            });
            var s = t.globalData.htGet, x = [ {
                keyword: "交易概述",
                keyname: "summary",
                text: s.summary
            }, {
                keyword: "甲方义务",
                keyname: "obliga",
                text: s.obliga
            }, {
                keyword: "乙方义务",
                keyname: "obligb",
                text: s.obligb
            }, {
                keyword: "丙方义务",
                keyname: "obligc",
                text: s.obligc
            }, {
                keyword: "验收条款",
                keyname: "accept",
                text: s.accept
            }, {
                keyword: "违约责任",
                keyname: "liabity",
                text: s.liabity
            }, {
                keyword: "免责事由",
                keyname: "execept",
                text: s.execept
            }, {
                keyword: "争议解决",
                keyname: "dispute",
                text: s.dispute
            }, {
                keyword: "其他条款",
                keyname: "end",
                text: s.end
            } ];
            x.slice(1, 4).filter(function(t) {
                return t.text && t.text.length > 0;
            });
            x[1].text && x[1].text.length > 0 && (x[1].text = x[1].text.map(function(t) {
                return x[1].text.indexOf(t) + 1 + "、" + t + "\n";
            }).join("")), x[2].text && x[2].text.length > 0 && (x[2].text = x[2].text.map(function(t) {
                return x[2].text.indexOf(t) + 1 + "、" + t + "\n";
            }).join("")), x[3].text && x[3].text.length > 0 && (x[3].text = x[3].text.map(function(t) {
                return x[3].text.indexOf(t) + 1 + "、" + t + "\n";
            }).join("")), void 0 !== x[8].text && null !== x[8].text && x[8].text.length > 0 && (x[8].text = x[8].text.map(function(t) {
                return x[8].text.indexOf(t) + 1 + "、" + t + "\n";
            }).join(""));
            for (var d = x.filter(function(t) {
                return void 0 !== t.text && null !== t.text && t.text.length > 0;
            }), u = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ], c = 0, h = d.length; c < h; c++) d[c].inDex = u[c];
            this.setData({
                clause: x,
                clauselist: d
            });
        } else wx.showToast({
            title: "数据加载中",
            icon: "loading",
            duration: 2e4
        }), wx.request({
            url: t.url + "addon/" + n,
            data: {
                id: i
            },
            method: "GET",
            header: {
                "Content-Type": "application/json",
                Cookie: "PHPSESSID=" + wx.getStorageSync("PHPSESSID")
            },
            success: function(e) {
                t.globalData.htGet = e.data;
                var i = e.data.obliga, n = e.data.obligb, o = e.data.obligc, l = e.data.end;
                i && i.length > 0 && (t.globalData.htGet.obliga = i.split("【&#下一条：^//////】"), i = i.split("【&#下一条：^//////】")), 
                n && n.length > 0 && (t.globalData.htGet.obligb = n.split("【&#下一条：^//////】"), n = n.split("【&#下一条：^//////】")), 
                l && l.length > 0 && (t.globalData.htGet.end = l.split("【&#下一条：^//////】"), l = l.split("【&#下一条：^//////】")), 
                o && o.length > 0 && (t.globalData.htGet.obligc = o.split("【&#下一条：^//////】"), o = o.split("【&#下一条：^//////】")), 
                a.setData({
                    ht: t.globalData.htGet
                });
                var r = [ {
                    keyword: "交易概述",
                    keyname: "summary",
                    text: e.data.summary
                }, {
                    keyword: "甲方义务",
                    keyname: "obliga",
                    text: i
                }, {
                    keyword: "乙方义务",
                    keyname: "obligb",
                    text: n
                }, {
                    keyword: "丙方义务",
                    keyname: "obligc",
                    text: o
                }, {
                    keyword: "验收条款",
                    keyname: "accept",
                    text: e.data.accept
                }, {
                    keyword: "违约责任",
                    keyname: "liabity",
                    text: e.data.liabity
                }, {
                    keyword: "免责事由",
                    keyname: "execept",
                    text: e.data.execept
                }, {
                    keyword: "争议解决",
                    keyname: "dispute",
                    text: e.data.dispute
                }, {
                    keyword: "其他条款",
                    keyname: "end",
                    text: l
                } ];
                r.slice(1, 4).filter(function(t) {
                    return t.text && t.text.length > 0;
                });
                r[1].text && r[1].text.length > 0 && (r[1].text = r[1].text.map(function(t) {
                    return r[1].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), r[2].text && r[2].text.length > 0 && (r[2].text = r[2].text.map(function(t) {
                    return r[2].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), r[3].text && r[3].text.length > 0 && (r[3].text = r[3].text.map(function(t) {
                    return r[3].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join("")), void 0 !== r[8].text && null !== r[8].text && r[8].text.length > 0 && (r[8].text = r[8].text.map(function(t) {
                    return r[8].text.indexOf(t) + 1 + "、" + t + "\n";
                }).join(""));
                for (var s = r.filter(function(t) {
                    return void 0 !== t.text && null !== t.text && t.text.length > 0;
                }), x = [ "一", "二", "三", "四", "五", "六", "七", "八", "九", "十" ], d = 0, u = s.length; d < u; d++) s[d].inDex = x[d];
                a.setData({
                    clause: r,
                    clauselist: s
                }), wx.hideToast();
            },
            fail: function(t) {
                wx.hideToast(), wx.showToast({
                    title: "无法连接网络",
                    icon: "loading",
                    duration: 2200
                });
            }
        });
    },
    toIndex: function() {
        this.data.sessin == t.globalData.PHPSESSID ? wx.navigateBack({
            delta: -1
        }) : wx.switchTab({
            url: "../Draft/Draft"
        });
    },
    lastsave: function(t) {
        var e = this.data.obliga;
        e && this.setData({
            obliga2: e.join("")
        });
        var a = this.data.obliga2, i = this.data.parties, n = this.data.preface, o = this.data.title;
        wx.request({
            url: "http://localhost/wapcms/index.php?s=/addon/Contract/Contract/addContract",
            data: {
                obliga: a,
                parties: i,
                preface: n,
                title: o
            },
            method: "GET",
            header: {
                "Content-Type": "application/json"
            },
            success: function(t) {
                wx.redirectTo({
                    url: "../reviewask/reviewask"
                }), t && (wx.showToast({
                    title: "保存成功",
                    icon: "success",
                    duration: 2e3
                }), wx.removeStorage({
                    key: "obliga"
                }), wx.removeStorage({
                    key: "parties"
                }), wx.removeStorage({
                    key: "preface"
                }), wx.removeStorage({
                    key: "title"
                }));
            },
            fail: function(t) {
                t && wx.showToast({
                    title: "保存失败，请检查网络连接",
                    icon: "loading",
                    duration: 2600
                });
            }
        });
    },
    onShareAppMessage: function(t) {
        var e = this.data.id, a = (this.data.url, this.data.sessin), i = this.data.Listurl, n = this.data.TopName;
        return {
            title: this.data.ht.title,
            path: "/pages/MySht2/MySht2?id=" + e + "&url=" + i + "ContractDetail&url2=" + i + "editContract&sessin=" + a + "&Listurl=" + i + "&TopName=" + n,
            success: function(t) {
                console.log(t);
            },
            fail: function(t) {}
        };
    }
});